package com.molihub.config;

import com.molihub.component.LoginHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import sun.net.www.content.image.png;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/user-info").setViewName("u-admin/user-info");
        registry.addViewController("/update-user-info").setViewName("u-admin/update-user-info");
        registry.addViewController("/otherProfilePage").setViewName("otherProfilePage");

    }
    /**
     * 注册登录拦截器
     * addPathPatterns() -> 拦截的请求
     * excludePathPatterns -> 不拦截的请求
     * 两个方法的参数都是可变字符串参数
     * SpringBoot已经做好了对静态资源的映射
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(
                        "/","/index.html","/login","/login.html","/register","/admin","/file/share",
                        "/sendCode","/loginByQQ","/connection","/index/articles/**",
                        "/asserts/**","/**/*.css", "/**/*.js", "/**/*.png ", "/**/*.jpg"
                        ,"/**/*.jpeg","/**/*.gif", "/**/fonts/*", "/**/*.svg");
    }
}
